<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>ifa-主页</title>
	<link rel="stylesheet" href="../src/css/bootstrap.min.css" />
	<link rel="stylesheet" href="../public/css/my_style.css" />
	<style type="text/css">
		#app {
			text-align: center;
			padding-top: 100px;
		}
	</style>
</head>

<body>
	<div id="app">
		{{out}}
		<m_money :out="out" :parent_value="parent_value" :control_type="control_type"></m_money>
	</div>
	<script src="../src/jquery.js"></script>
	<script src="../src/js/jquery.nicescroll.js"></script>
	<script src="../src/js/common-scripts.js"></script>
	<script src="../public/js/comm.js"></script>
	<script src="../src/js/bootstrap.min.js"></script>
	<script src="../src/vue.min.js"></script>
	<script src="form_com.js"></script>
	<script type="text/x-template" id="money">
		<form class="my_container">

			<template v-for="(item1,index) in parent_value">
				<div class="form-group" v-if="item1.Level==1">
					<label for="exampleInputEmail1">{{item1.CategoryName}}</label>
				</div>
				<div class="form-group" v-for="(item2,index2) in parent_value" v-if="item2.ParentID==item1.ID">
					<template v-if="control_type==9">
						<label for="exampleInputEmail1">多选：{{item2.CategoryName}}</label>
						<div>
							<label class="checkbox-inline">
								<input type="checkbox" v-model="component_values" v-bind:id="item2.ID" v-bind:value="item2.ID+'|A'"> {{item2.LastTitle1}}
							</label>
							<label class="checkbox-inline">
								<input type="checkbox" v-model="component_values" v-bind:id="item2.ID"  v-bind:value="item2.ID+'|B'"> {{item2.LastTitle2}}
							</label>
						</div>
					</template>
					<template v-if="control_type==10">
						<label for="exampleInputEmail1">单选：{{item2.CategoryName}}</label>
						<div>
							<label class="checkbox-inline">
								<input type="radio" v-model="radio_values[index2]" v-bind:value="item2.ID+'|A'" > {{item2.LastTitle1}}
							</label>
							<label class="checkbox-inline">
								<input type="radio" v-model="radio_values[index2]" v-bind:value="item2.ID+'|B'" > {{item2.LastTitle2}}
							</label>
						</div>
					</template>
				</div>
			</template>
		</form>
	</script>


	<script type="text/javascript">
		Vue.component('m_money', {
			template: '#money',
			data: function () {
				return {
					selectedIds: "",
					component_values: [],
					radio_values: ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
				}
			},
			props: ['parent_value', "control_type", "out"],
			watch: {
				component_values: function (val, oldval) {
					this.updateValue(val);
				}, radio_values: function (val, oldval) {
					this.updateValue(val);
				}
			},
			methods: {
				updateValue: function (val) {
					var self = this;
					//题目规则
					var value = "";
					self.selectedIds = "";
					$(val).each(function (index, item) {
						if (item.indexOf("|") > -1) {
							self.selectedIds += item.split('|')[0] + ",";
							var v = item.split('|')[1];
							if (!value)
								value = v;
							if (v == "B")
								value = v;
						}
					})

					self.out.result = value;
					self.out.all_values = self.removeEmpty(val);
					//进行赋值
					//this.$emit('input', value == "0" ? "A" : "B");

					this.checkRequired();
				},
				removeEmpty: function (v) {
					var newVue = "";
					$(v).each(function (i, item) {
						if (item.indexOf("|") > -1) {
							newVue += item.replace('|', ',') + ";"
						}
					});
					return newVue;
				},
				checkRequired: function () {
					var self = this;
					var isSelected = false;
					var msg = "";
					var requiredIds = self.getRequiredIds();
					$(requiredIds).each(function (i, item) {

						isSelected = false;
						$(item.Ids).each(function (si, id) {
							if (self.selectedIds.indexOf(id) == -1) {
								isSelected = true;
								return false;
							}
						});

						if (isSelected) {
							msg = item.CategoryName;
							return false;
						}
					})

					if (isSelected) {
						//alert(msg + "必选");
					}
				},
				getRequiredIds: function () {
					var self = this;
					var requiredTypeIds = [];
					$(self.parent_value).each(function (i, item) {
						if (item.IsRequired) {
							requiredTypeIds.push(item);
						}
					});

					var requiredIds = [];
					$(requiredTypeIds).each(function (pIndex, pItem) {
						$(self.parent_value).each(function (i, item) {
							if (item.ParentID == pItem.ID) {
								var existPId = self.getExistPId(requiredIds, pItem.ID);
								if (!existPId) {
									existPId = {};
									existPId.ParentID = pItem.ID;
									existPId.CategoryName = pItem.CategoryName;
									existPId.Ids = [];
									requiredIds.push(existPId);
								}
								existPId.Ids.push(item.ID);
							}
						});
					});
					return requiredIds;
				},
				getExistPId: function (rIds, pid) {
					var bExist = null;
					$(rIds).each(function (i, item) {
						if (item.ParentID == pid) {
							bExist = item;
							return false;
						}
					});
					return bExist;
				}
			},
			mounted: function () {
				console.log("child mounted");
			},
			beforeUpdate: function () {
				console.log("child beforeUpdate");

			},
			updated: function () {
				console.log("child updated");

			}
		})



		var app = new Vue({
			el: '#app',
			data: {
				parent_value: [],
				control_type: "10",
				out: { result: '', all_values: [] }
			}, mounted: function () {
				//离岸信托的资产类型
				var assetTypeData = [
					{
						"ID": "16e43ad9-3c40-4858-9513-c7c5f5cd6d7d",
						"CategoryName": "其他（如豪车、游艇、私人飞机等）",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "382b3344-253d-41e1-96c1-68595dac8d26",
						"CategoryName": "其他金融类投资产品（如基金、债券、期货、私募、银行理财等）",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "46129b72-916c-4aef-b45e-fc6238390d3a",
						"CategoryName": "特殊资产（如古董、艺术品、宝石、贵金属等）",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "5a40feac12ef4c0f9902e7ece73ae9aa",
						"CategoryName": "美元",
						"IsRequired": null,
						"ParentID": "16ac988a3acc4c09b9c45a64fe9b80ff",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "7c8faee2-cf9b-4e27-a773-174c8b5d6729",
						"CategoryName": "保险",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "a0c0cfae-98d5-4efe-9c18-6d3f7df84644",
						"CategoryName": "房地产",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "b9f03670-4bca-4e06-9cde-c912928321ce",
						"CategoryName": "股票",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "d0670e20fbb24cfb951256cc42738254",
						"CategoryName": "人民币",
						"IsRequired": null,
						"ParentID": "16ac988a3acc4c09b9c45a64fe9b80ff",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "fcb4fcad-f862-43ce-8284-70ea19508e43",
						"CategoryName": "非上市公司股权",
						"IsRequired": null,
						"ParentID": "1cf898f710e44ff888b4ddc67289fa6f",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": null,
						"ClassName": null
					},
					{
						"ID": "16ac988a3acc4c09b9c45a64fe9b80ff",
						"CategoryName": "存款",
						"IsRequired": true,
						"ParentID": null,
						"Level": 1,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 1,
						"ClassName": null
					},
					{
						"ID": "551a6702-e9fc-4cf4-997f-fd927601b3f3",
						"CategoryName": "股票",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 1,
						"ClassName": null
					},
					{
						"ID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"CategoryName": "其他资产",
						"IsRequired": false,
						"ParentID": null,
						"Level": 1,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 2,
						"ClassName": null
					},
					{
						"ID": "8269ec85-926f-497b-a868-f3d9d56fa22a",
						"CategoryName": "非上市公司股权",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 2,
						"ClassName": null
					},
					{
						"ID": "b64577ac-e1d5-4410-abaf-0d71e526b3bc",
						"CategoryName": "保险",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 3,
						"ClassName": null
					},
					{
						"ID": "14260f23-948f-4f51-82e9-1f9bde6ebeef",
						"CategoryName": "房地产",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 4,
						"ClassName": null
					},
					{
						"ID": "6b8e02a8-62c3-40e5-b4f0-bd09ba77d867",
						"CategoryName": "其他金融投资产品（如基金、债券、期货、私募、银行理财等）",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 5,
						"ClassName": null
					},
					{
						"ID": "13889ff2-1252-48cc-8046-de018dee3109",
						"CategoryName": "特殊资产（如古董、艺术品、宝石、贵金属等）",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 6,
						"ClassName": null
					},
					{
						"ID": "a66b6a92-cf15-4af5-afb6-69f0cc1c5f12",
						"CategoryName": "其他（如豪车、游艇、私人飞机等）",
						"IsRequired": null,
						"ParentID": "7b85037e-d492-4724-b675-b94c8ca474d0",
						"Level": 2,
						"Title": "资产类型列表",
						"LastTitle1": "境内",
						"LastTitle2": "境外",
						"SequenceNo": 7,
						"ClassName": null
					}
				];

				this.parent_value = assetTypeData;
				console.log("parent mounted");
			}, methods: {
			}
		})
	</script>
</body>

</html>